define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'call/cdr/index',
                    add_url: 'call/cdr/add',
                    edit_url: 'call/cdr/edit',
                    del_url: 'call/cdr/del',
                    multi_url: 'call/cdr/multi',
                    table: 'cdr',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: true,
                exportTypes: ['excel'],
                showColumns: false,
                columns: [
                    [
                        /*{checkbox: true},*/
                        {field: 'id', title: __('Id')},
                        /*field: 'caller_id_name', title: __('Caller_id_name'), formatter: function(value, row, index, field) { return __(value); }},
                        {field: 'caller_id_number', title: __('Caller_id_number')},*/
                        {field: 'gateway', title: __('Gateway'), formatter: Table.api.formatter.label },
                        /*{field: 'destination_number', title: __('Destination_number')},*/
                        {field: 'context', title: __('Context'), formatter: function(value, row, index, field) { return __(value); }},
                        {field: 'peer_number', title: __('对方号码')},
                        {field: 'start_stamp', title: __('Start_stamp'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'answer_stamp', title: __('Answer_stamp'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'end_stamp', title: __('End_stamp'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'duration', title: __('Duration')},
                        {field: 'billsec', title: __('Billsec')},
                        {field: 'billmin', title: __('计费时长(分)')},
                        {field: 'hangup_cause', title: __('Hangup_cause'), formatter: function(value, row, index, field) { return __(value); } },
                        /*{field: 'bridge_hangup_cause', title: __('Bridge_hangup_cause'), formatter: function(value, row, index, field) { return __(value); } },
                        {field: 'uuid', title: __('Uuid')},
                        {field: 'bleg_uuid', title: __('Bleg_uuid')},
                        {field: 'accountcode', title: __('Accountcode')},
                        {field: 'domain_name', title: __('Domain_name')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}*/
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
